<link rel="stylesheet" href="/static/public/vendor/bootstrap-switch/bootstrap-switch.min.css">
<script src="/static/public/vendor/bootstrap-switch/bootstrap-switch.min.js"></script>
<form id="myForm" autocomplete="off" data-validator-option="{theme:'default'}">
    <input type="hidden" name="id" value="$!{project.id}">
    <div class="form-group">
        <label class="control-label">项目名称：</label>
        <input type="text" class="form-control" value="$!{project.name}" name="name">
    </div>
    <div class="hr-line-dashed"></div>
    <div class="form-group">
        <label class="control-label">项目描述：</label>
        <textarea class="form-control" name="content" style="resize: none;height: 80px">$!{project.content}</textarea>
    </div>
    #if($!{project})
    <div class="form-group">
        <div class="switch" data-on="danger" data-off="primary" data-on-label="有效" data-off-label="无效">
            <input type="hidden" id="state" name="state" value="$project.state">
            <input type="checkbox" #if($project.state=='1') checked #end/>
        </div>
    </div>
    #end
</form>
<div class="modal-footer">
    <button class="btn btn-primary add-top-menu" onclick="saveProject()">保存</button>
    <a class="btn btn-default" data-dismiss="modal" href="#">取消</a>
</div>
<script src="/static/plugins/nice-validator-0.8.1/jquery.validator.js?local=zh-CN"></script>
<script type="text/javascript">
    function saveProject() {
        $("#myForm").submit();
    }
    $(function () {
        $('.switch').on('switch-change', function (e, data) {
            $("#state").val(data.value ? "1" : "0");
        });
        $("#myForm").validator({
            valid: function (form) {
                var me = this;
                me.holdSubmit();
                $.ajax({
                    url: "/sys/project/save",
                    data: $(form).serialize(),
                    type: "POST",
                    success: function (data) {
                        var d = JSON.parse(data);
                        if (d.success && d.data) {
                            $("#dialog").modal('hide');
                            reloadData();
                            toastr.success("保存成功!", "消息提示");
                        } else {
                            toastr.warning("操作失败!");
                            me.holdSubmit(false);
                        }
                    }
                });
            }
        });
    });
</script>
</body>
</html>
